<template>
  <transition name="custom" @after-leave="handleAfterLeave">
    <div class="toast-box" v-show="show">
      {{ text }}
    </div>
  </transition>
</template>

<script setup>
import {ref, render} from 'vue'

const props = defineProps({
  text: [String]
})
const emit = defineEmits(['hide'])
function handleAfterLeave() {
  render(null, document.body)
}
const show = ref(false)
defineExpose({
  show
})
</script>

<style lang="scss" scoped>
.toast-box {
  position: fixed;
  inset: 0;
  z-index: 999;
  padding: 20px;
  width: fit-content;
  height: fit-content;
  flex-shrink: 0;
  border-radius: 12px;
  background: #0000007a;
  color: #ffffff;
  font-size: 16px;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
.custom-enter-active,
.custom-leave-active {
  -webkit-transition: opacity .2s linear;
  transition: opacity .2s linear
}

.custom-enter-from,
.custom-leave-to {
  opacity: 0
}
</style>
